package com.neulogistics.contrib.procuredcenter.api.application.converter;

import cn.hutool.json.JSONUtil;
import com.neulogistics.contrib.procuredcenter.api.application.viewmodel.VendorViewModel;
import com.neulogistics.contrib.procuredcenter.domain.model.valueobject.Address;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.orm.po.VendorPO;
import org.springframework.beans.BeanUtils;

public class VendorPOVMConverter {
    public static VendorViewModel POToVM(VendorPO vendorPO){
        if (vendorPO == null)
            return null;

        VendorViewModel vendorViewModel = new VendorViewModel();
        BeanUtils.copyProperties(vendorPO, vendorViewModel);
        // json对象转换
        vendorViewModel.setVendorAddress(JSONUtil.toBean(vendorPO.getVendorAddress(), Address.class));

        return vendorViewModel;
    }
}
